package com.choichumgming.rentcat.service.Impl;

import com.choichumgming.rentcat.dao.OrderReturnParamDao;
import com.choichumgming.rentcat.dto.OrderReturnParam;
import com.choichumgming.rentcat.mapper.OmsOrderItemMapper;
import com.choichumgming.rentcat.mapper.OmsOrderMapper;
import com.choichumgming.rentcat.model.OmsOrder;
import com.choichumgming.rentcat.model.OmsOrderExample;
import com.choichumgming.rentcat.service.OmsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OmsOrderServiceImpl implements OmsOrderService {

    @Autowired
    private OmsOrderMapper orderMapper;

    @Autowired
    private OmsOrderItemMapper orderItemMapper;

    @Autowired
    private OrderReturnParamDao orderReturnParamDao;

    /**
     * 删除订单记录
     */
    @Override
    public void deleteOrder(Long orderId) {
        orderMapper.deleteByPrimaryKey(orderId);
    }

    /**
     * 根据userId和订单状态查询全部订单
     */
    @Override
    public List<OmsOrder> getStautsList(Long userId, int status) {
        OmsOrderExample example = new OmsOrderExample();
        example.createCriteria().andStatusEqualTo(status).andBuyUserIdEqualTo(userId);
        List<OmsOrder> orderList = orderMapper.selectByExample(example);
        return orderList;
    }

    @Override
    public List<OmsOrder> getList(Long userId) {
        OmsOrderExample example = new OmsOrderExample();
        example.createCriteria().andBuyUserIdEqualTo(userId);
        List<OmsOrder> orderList = orderMapper.selectByExample(example);
        return orderList;
    }

    @Override
    public OrderReturnParam getitem(Long orderId) {


        OrderReturnParam orderReturnParam = orderReturnParamDao.getAllOrderList(orderId);

        return orderReturnParam;
    }

    @Override
    public int updateOrderStatus(Long orderId, int status) {
        OmsOrderExample example = new OmsOrderExample();
        example.createCriteria().andOrderIdEqualTo(orderId);
        OmsOrder omsOrder = new OmsOrder();
        omsOrder.setStatus(status);

        return orderMapper.updateByExampleSelective(omsOrder, example);
    }
}
